﻿Imports System.Data.SqlClient

Public Class Product

    Private Sub Product_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cn As New SqlConnection()
        cn.ConnectionString = "Server =DELL-PC\SQLEXPRESS; Database = SaleManagement; UID = sa; PWD = 123"
        cn.Open()

        Dim cmd As New SqlCommand()
        cmd.Connection = cn
        cmd.CommandText = "SELECT * From product;"
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        While reader.Read()
            DataGridView1.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))

        End While
        reader.Close()
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        Dim cn As New SqlConnection()
        cn.ConnectionString = "Server =DELL-PC\SQLEXPRESS; Database = SaleManagement; UID = sa; PWD = 123"
        cn.Open()
        Dim cmd As New SqlCommand()
        cmd.Connection = cn
        cmd.CommandText = "insert into product values (N'" & txtproname.Text & "',N'" & txtsupid.Text & "',N'" & txtcatid.Text & "',N'" & txtunit.Text & "',N'" & txtpric.Text & "')"
        cmd.ExecuteNonQuery()
        Me.Refresh()
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
End Class